package net.zjitc.servlet.goods;

import net.zjitc.domain.Goods;
import net.zjitc.service.GoodsService;
import net.zjitc.service.impl.GoodsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "UpdateGoodServlet",urlPatterns = "/updateGood")
public class UpdateGoodServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        //1、获取前端传过来的数据
        String id = request.getParameter("id");
        String name = request.getParameter("name");
        String price = request.getParameter("price");
        String info = request.getParameter("info");
        //
        Goods goods = new Goods(Integer.parseInt(id),name,null, Float.parseFloat(price),info);
        //更新
        GoodsService goodsService = new GoodsServiceImpl();
        int num = goodsService.update(goods);

        //页面list
        String contextPath = request.getContextPath();
        response.sendRedirect(contextPath+"/goodsList");

    }
}
